<%--
  Created by IntelliJ IDEA.
  User: 周文涛
  Date: 2020/7/22
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>退单申请管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">退单申请号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="refundId" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">订单号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="ordersId" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">退单状态</label>
                    <div class="layui-input-inline">
                        <select name="refundStatus">
                            <option value="">全部</option>
                            <option value="0">未同意</option>
                            <option value="1">已同意</option>
                        </select>
                    </div>
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="accountName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <input type="text" id="startTime" name="startTime" class="layui-input" placeholder="开始时间">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline" class="layui-input">
                        <input type="text" id="endTime" name="endTime" class="layui-input" placeholder="结束时间">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="refund_list" lay-filter="refund_list"></table>
            <script type="text/html" id="table-content-list">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="details"><i class="layui-icon layui-icon-edit"></i>查看详情</a>
                {{# if(d.refundStatus == 0){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update">同意</a>
                {{# }else{ }}
                <a class="layui-btn layui-btn-warm layui-btn-xs">已同意</a>
                {{# } }}
            </script>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/back/layuiadmin/layui/layui.js"></script>

<script type="text/javascript">

</script>
<script>
    layui.config({
        base: '${pageContext.request.contextPath}/back/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['table','laydate','form'], function(){
        var table = layui.table,
            laydate = layui.laydate,
            form = layui.form,
            $ = layui.$;

        var cols=[[ //表头
            {field: 'refundId', title: '退票申请号', sort: true, width:200, fixed: 'left'}
            ,{field: 'ordersId', title: '订单号', sort: true, width:200,templet:'<div>{{d.orders.ordersId}}</div>'}
            ,{field: 'accountName', title: '用户名称', sort: true, width:120,templet:'<div>{{d.orders.account.accountName}}</div>'}
            ,{field: 'refundTime', title: '申请时间', sort: true, width: 250}
            ,{field: 'refundContent', title: '内容', width: 150, sort: true}
            ,{field: 'refundPrice', title: '退款金额', width:120, sort: true}
            ,{field: '', title: '操作', width: 200,toolbar:"#table-content-list"}

        ]]

        table.render({
            elem: '#refund_list'
            ,url: '${pageContext.request.contextPath}/back/refund' //数据接口
            ,page: true //开启分页
            ,cols: cols
            ,parseData:function(res){
                return {
                    "code": 0, //解析接口状态
                    "msg": "搜索成功", //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.list, //解析数据列表
                };
            }
        });

        form.on('submit(search)',function(data){
            var field = data.field;
            layer.msg("正在搜索");
            table.render({
                elem: '#refund_list'
                ,url: '${pageContext.request.contextPath}/back/refund' //数据接口
                ,where: field
                ,page: true //开启分页
                ,cols: cols
                ,parseData:function(res){
                    return {
                        "code": 0, //解析接口状态
                        "msg": "", //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.list, //解析数据列表
                    };
                }
            });
        });

        laydate.render({
            elem: '#startTime' //指定元素
            ,type:'datetime'
        });
        laydate.render({
            elem: '#endTime' //指定元素
            ,type:'datetime'
        });

        table.on('tool(refund_list)',function(obj){
            var refundId = obj.data.refundId;
            if(obj.event == 'details'){
                layer.open({
                    type: 2
                    ,title:"查看退单申请详情"
                    ,content:"${pageContext.request.contextPath}/back/views/order/refundDetails.jsp?refundId="+refundId
                    ,area: ['550px', '550px']
                    ,btn: ['确定', '取消']
                });
            }
            if(obj.event == "update"){
                $.ajax({
                    url:"${pageContext.request.contextPath}/back/refund/"+refundId
                    ,type:"put"
                    ,success:function(result) {
                        if (result) {
                            layer.confirm("退票成功",function(){
                                location.reload();
                            })
                        } else {
                            layer.msg("操作失败");
                        }
                    }
                    ,error:function(){
                        layer.msg("ajax请求失败");
                    }
                });
            }
        });

    });
</script>
</body>
</html>

